package prj.carmap.mobile.util;

import java.io.UnsupportedEncodingException;

import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;

import prj.carmap.mobile.CarmapApplication;
import prj.carmap.mobile.model.UserInfo;

/**
 * 访问日志工具类
 *
 */
public class AccessLogUtil {

	/**
	 * @param sellerId
	 * 				商家id
	 * @param sellerPhone
	 * 				商家电话
	 * @return
	 */
	public static StringEntity createAccessLogParam(String sellerId, String sellerPhone) {
		UserInfo userInfo = CarmapApplication.getInstance().userInfo;
		if (userInfo == null)
			return null;

		try {
			JSONObject jsonParams = new JSONObject();
			jsonParams.put("userPhone", userInfo.phone);
			jsonParams.put("cardNo", userInfo.cardNo);
			jsonParams.put("longitude", CarmapApplication.getInstance().getLocData().longitude);
			jsonParams.put("latitude", CarmapApplication.getInstance().getLocData().latitude);
			jsonParams.put("sellerId", sellerId);
			jsonParams.put("sellerPhone", sellerPhone);
			jsonParams.put("recordType", 2);
			StringEntity entity = new StringEntity(jsonParams.toString());
			return entity;
		}
		catch (JSONException e) {
			e.printStackTrace();
		}
		catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
	

	/**
	*日志类型
	* @Title: createAccessLogTypeParam
	* @param type
	* @return
	* @return StringEntity
	* @throws
	* @author huangsq
	*/
	public static StringEntity createAccessLogTypeParam(Integer type) {
		UserInfo userInfo = CarmapApplication.getInstance().userInfo;
		if (userInfo == null)
			return null;

		try {
			JSONObject jsonParams = new JSONObject();
			jsonParams.put("userPhone", userInfo.phone);
			jsonParams.put("cardNo", userInfo.cardNo);
//			jsonParams.put("longitude", CarmapApplication.getInstance().getLocData().longitude);
//			jsonParams.put("latitude", CarmapApplication.getInstance().getLocData().latitude);
//			jsonParams.put("sellerId", sellerId);
//			jsonParams.put("sellerPhone", sellerPhone);
			jsonParams.put("recordType", type);
			StringEntity entity = new StringEntity(jsonParams.toString());
			return entity;
		}
		catch (JSONException e) {
			e.printStackTrace();
		}
		catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
}
